package com.xq.shop.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xq.shop.dao.IPointDAO;
import com.xq.shop.po.Point;
import com.xq.shop.util.DateUtil;
import com.xq.shop.util.HibernateUtil;

@Repository
public class PointDAO extends BaseDAO<Point> implements IPointDAO{

	@Override
	@SuppressWarnings("unchecked")
	public Point get(Long userID, Date date) {
		
		String year = DateUtil.format(date, DateUtil.FORMAT_05);
		List<Point> list = HibernateUtil.getTemplate().find(" from Point where user_id=? and year=?", new Object[]{userID, year});
		if(list != null && list.size() > 0){
			return list.get(0);
		} else {
			return null;
		}
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Point> get(Long userId, Integer status) {
		
		String hql = " from Point where user_id=:userId and status=:status order by year desc";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("userId", userId);
		param.put("status", status);
		return (List<Point>) HibernateUtil.executeFind(hql, param);
	}
}
